<?php

namespace app\adminmini\service;

use think\facade\Db;

class SetcabinetService extends BaseService
{
    public function getUserInfo($userId)
    {

        $info = Db::name('customer_set_cabinet')->where('store_id', '=', $userId)->find();


        if (!$info) {
            $info['appId'] = '';
        }
        return message("操作成功", true, $info);
    }

    public function updateUserInfo($userId)
    {


        // 参数
        $param = request()->param();

        $data = [
            'appId' => $param['appId'],
            'appkey' => isset($param['appkey']) ? $param['appkey'] : '',
            'store_id' => $userId,
            'time' => isset($param['time']) ? $param['time'] : 0,
            'admin_time' => isset($param['admin_time']) ? $param['admin_time'] : 90,
            'door_distance' => isset($param['door_distance']) ? $param['door_distance'] : 0,

        ];
        $info = Db::name('customer_set_cabinet')->where('store_id', '=', $userId)->find();
        if ($info) {
            $result = Db::name('customer_set_cabinet')->where('store_id', '=', $userId)->update($data);
        } else {
            $result = Db::name('customer_set_cabinet')->insert($data);
        }

        if (!$result) {
            return message("更新资料信息失败", false);
        }
        return message("更新资料信息成功");
    }
}